const UniPayService = require('./unipay.js')
const uniPay = require('uni-pay');
/**
 * 线下转账
 */
module.exports = class OfflinepayService extends UniPayService {
	constructor(ctx) {
		super(ctx)
		this.type = "offlinepay";
		this.payname = "线下转账";
	}
	async prepay(userInfo) {
		return {
			key: this.type,
			icon: "duozhongzhifu",
			color: "#00aa7f",
			name: this.payname,
			confirm: true
		}
	}
	/**
	 * 创建支付订单
	 */
	async app(order, userInfo, next, preview, update) {
		console.log("线下转账");
		let platform = this.ctx.context.PLATFORM;
		let {
			content
		} = this.ctx.getConfigs.platformConfigs("payment.offlinepay")
		let res = {
			transaction_id: Math.random().toString().substr(2),
			outTradeNo: order.outTradeNo,
			platform: platform,
			message: "下单成功,去转账",
			detail: true,
			tradeStatus: "TRADE_SUCCESS",
			totalFee: 0,
			type: this.type,
			name: this.payname
		};
		//仅仅更新信息
		let res2 = await update({
			payInfo: {
				time: Date.now(),
				...res
			},
			offlinepay: {
				message: "等待线下付款",
				content,
			}
		});
		console.log("线下转账完成，回调逻辑", res2);
		return res;
	}

	async refund() {}
}
